package appIdeasScrumer.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import appIdeasScrumer.excepcion.DAOExcepcion;
import appIdeasScrumer.modelo.Cobro;
import appIdeasScrumer.modelo.Tarifa;
import appIdeasScrumer.negocio.GestionCentroFormacion;
import appIdeasScrumer.negocio.GestionCobro;
import appIdeasScrumer.negocio.GestionTarifa;
import appIdeasScrumer.util.ConexionBD;

public class TarifaDAO extends BaseDAO {

	public Collection<Tarifa> obtener() throws DAOExcepcion {
		
		Collection<Tarifa> ctarifa= new ArrayList<Tarifa>();
		Connection cnx = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			cnx = ConexionBD.obtenerConexion();
			String query = "select cod_tarifa, mon_tarifa from tc_tarifas order by cod_tarifa";
			stmt = cnx.prepareStatement(query);
			rs = stmt.executeQuery();
			while (rs.next()) {
				
				Tarifa tarifa = new Tarifa();
				
				tarifa.setCodTarifa(rs.getInt("cod_tarifa"));
				tarifa.setValorTarifa(rs.getDouble("mon_tarifa"));
				ctarifa.add(tarifa);
			}
	
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarResultSet(rs);
			this.cerrarStatement(stmt);
			this.cerrarConexion(cnx);
		}
		return ctarifa;

	}

}
